package _01_动态数组;

public class _240_搜索二维矩阵II {

    public static void main(String[] args) {
        _240_搜索二维矩阵II v = new _240_搜索二维矩阵II();

        int[][] ins = {{-5}};
        System.out.println(v.searchMatrix(ins, -10));
    }

    public boolean searchMatrix(int[][] matrix, int target) {
        int rows = matrix.length;
        int cols = matrix[0].length;

        int row = 0;
        int col = cols - 1;
        while (row < rows && col >= 0) {
            // 目标值和当前值比较
            if (matrix[row][col] > target) col--;
            else if (matrix[row][col] < target) row++;
            else return true;
        }
        return false;
    }

}
